//
//  IdentificationViewController.m
//  jiyujiaProgram
//
//  Created by NiKi on 15/11/16.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "IdentificationViewController.h"
#import "IFirstCell.h"
#import "ISecondCell.h"
#import "IThirdCell.h"
#import "IFourthCell.h"


#define Section_Close 0 //收起
#define Section_Open  1 //展开


@interface IdentificationViewController () <UITableViewDataSource,UITableViewDelegate,firstDelegate,secondDelegate,thirdDelegate,fourthDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@end

@implementation IdentificationViewController
{
    
    UserInfoManager *_userInfo;
    UITableView *_tableView;
    NSMutableArray *_sectionStatus;
    UIActionSheet *_photoActionSheet;
    NSInteger chooseNum;
    NSData *_imageData;
    
    NSString *_firstPhoto;
    NSString *_firstId;
    NSString *_secondPhoto;
    NSString *_secondId;
    NSString *_thirdPhoto;
    NSString *_thirdId;
    NSString *_fourthPhoto;
    NSString *_fourthId;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatNavigationBarWithImage:nil title:@"认证设置"];
    [self creatNavigationBarLeftItemWithLeftTitle:nil LeftImage:ECIMAGENAME(@"back_button.png")];

    if (!_sectionStatus) {
        _sectionStatus = [[NSMutableArray alloc] initWithObjects:@(Section_Close),@(Section_Close),@(Section_Close),@(Section_Close), nil];
    }
    
    _userInfo = [UserInfoManager sharedUserInfoManager];
    [_userInfo loadUserInfoFromSanbox];
    
//    _firstPhoto = _userInfo.
    
    [self creatTableView];
}


- (void)leftBtnClick:(id)leftSender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)creatTableView
{
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ECSCREEN_W, ECSCREEN_H - 64) style:UITableViewStylePlain];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    _tableView.backgroundColor = BG_COLOR;
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    
    _tableView.tableFooterView = [[UIView alloc]init];
    
    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    [self.view addSubview:_tableView];
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80.f;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    BOOL isOpen = [_sectionStatus[section] boolValue];
    if (isOpen == NO) {
        return 0;
    }else{
        return 1;
    }
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 80.f;
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 80)];
    view.backgroundColor = ECCOLOR(255, 255, 255, 1);

    switch (section) {
        case 0:
        {
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 30)];
            label.backgroundColor = BG_COLOR;
            label.font = [UIFont systemFontOfSize:13.f];
            label.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:label];
            
            NSString *numString = @"(*必填)";
            NSString *baseString = [NSString stringWithFormat:@"     身份认证 %@",numString];
            NSRange range = [baseString rangeOfString: numString];
            
            NSMutableAttributedString*attribute = [[NSMutableAttributedString alloc] initWithString: baseString];
            [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor redColor]}range: range];
            
            label.text = baseString;
            label.attributedText = attribute;
            
            
            
            UILabel *desc = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, ECSCREEN_W - 80, 50)];
            desc.numberOfLines = 0;
            desc.text = @"日语+平台老师身份证必须为通过身份证的真是身份老师";
            desc.font = [UIFont systemFontOfSize:13.f];
            desc.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:desc];
            
            
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(ECSCREEN_W - 60, 40, 50, 30);
            button.tag = section;
            button.backgroundColor = NAVC_COLOR;
            [button setTitle:@"认证" forState:UIControlStateNormal];
            [button setTitleColor:ECCOLOR(255, 255, 255, 1) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:13.f];
            button.clipsToBounds = YES;
            button.layer.cornerRadius = 3;
            [button addTarget:self action:@selector(sectionClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
            
            return view;
            
        }
            break;
        case 1:
        {
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 30)];
            label.backgroundColor = BG_COLOR;
            label.font = [UIFont systemFontOfSize:13.f];
            label.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:label];
            
            NSString *numString = @"(尚未认证)";
            NSString *baseString = [NSString stringWithFormat:@"     学历认证 %@",numString];
            NSRange range = [baseString rangeOfString: numString];
            
            NSMutableAttributedString*attribute = [[NSMutableAttributedString alloc] initWithString: baseString];
            [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor lightGrayColor]}range: range];
            
            label.text = baseString;
            label.attributedText = attribute;

            
            UILabel *desc = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, ECSCREEN_W - 80, 50)];
            desc.numberOfLines = 0;
            desc.text = @"学历认证可以提升学生对个人主页学历背景的信任度";
            desc.font = [UIFont systemFontOfSize:13.f];
            desc.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:desc];

            
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(ECSCREEN_W - 60, 40, 50, 30);
            button.tag = section;
            button.backgroundColor = NAVC_COLOR;
            [button setTitle:@"认证" forState:UIControlStateNormal];
            [button setTitleColor:ECCOLOR(255, 255, 255, 1) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:13.f];
            button.clipsToBounds = YES;
            button.layer.cornerRadius = 3;
            [button addTarget:self action:@selector(sectionClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];

            
            return view;
        }
            break;
        case 2:
        {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 30)];
            label.backgroundColor = BG_COLOR;
            label.font = [UIFont systemFontOfSize:13.f];
            label.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:label];
            
            NSString *numString = @"(尚未认证)";
            NSString *baseString = [NSString stringWithFormat:@"     教师认证 %@",numString];
            NSRange range = [baseString rangeOfString: numString];
            
            NSMutableAttributedString*attribute = [[NSMutableAttributedString alloc] initWithString: baseString];
            [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor lightGrayColor]}range: range];
            
            label.text = baseString;
            label.attributedText = attribute;

            
            UILabel *desc = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, ECSCREEN_W - 80, 50)];
            desc.numberOfLines = 0;
            desc.text = @"教师认证可以提升学生对教师身份的信任度";
            desc.font = [UIFont systemFontOfSize:13.f];
            desc.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:desc];

            
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(ECSCREEN_W - 60, 40, 50, 30);
            button.tag = section;
            button.backgroundColor = NAVC_COLOR;
            [button setTitle:@"认证" forState:UIControlStateNormal];
            [button setTitleColor:ECCOLOR(255, 255, 255, 1) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:13.f];
            button.clipsToBounds = YES;
            button.layer.cornerRadius = 3;
            [button addTarget:self action:@selector(sectionClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];

            
            return view;
        }
            break;
        case 3:
        {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ECSCREEN_W, 30)];
            label.backgroundColor = BG_COLOR;
            label.font = [UIFont systemFontOfSize:13.f];
            label.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:label];
            
            NSString *numString = @"(尚未认证)";
            NSString *baseString = [NSString stringWithFormat:@"     专业资质认证 %@",numString];
            NSRange range = [baseString rangeOfString: numString];
            
            NSMutableAttributedString*attribute = [[NSMutableAttributedString alloc] initWithString: baseString];
            [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor lightGrayColor]}range: range];
            
            label.text = baseString;
            label.attributedText = attribute;
            
            

            
            UILabel *desc = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, ECSCREEN_W - 80, 50)];
            desc.numberOfLines = 0;
            desc.text = @"专证认证可以提升学生对专业教师技能的业资认可度";
            desc.font = [UIFont systemFontOfSize:13.f];
            desc.textColor = ECCOLOR(0, 0, 0, 1);
            [view addSubview:desc];

            
            
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(ECSCREEN_W - 60, 40, 50, 30);
            button.tag = section;
            button.backgroundColor = NAVC_COLOR;
            [button setTitle:@"认证" forState:UIControlStateNormal];
            [button setTitleColor:ECCOLOR(255, 255, 255, 1) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:13.f];
            button.clipsToBounds = YES;
            button.layer.cornerRadius = 3;
            [button addTarget:self action:@selector(sectionClick:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];

            
            return view;
        }
            break;
            
        default:
        {
            return nil;
        }
            break;
    }
}



- (void)sectionClick:(UIButton *)button
{
    BOOL isOpen = [_sectionStatus[button.tag] boolValue];
    [_sectionStatus replaceObjectAtIndex:button.tag withObject:@(!isOpen)];
    [_tableView reloadSections:[NSIndexSet indexSetWithIndex:button.tag] withRowAnimation:UITableViewRowAnimationFade];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *reuseIdentifier = @"ifirstCell";
        IFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (nil == cell) {
            NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"IFirstCell" owner:nil options:nil];
            for (NSObject *obj in arr) {
                if ([obj isKindOfClass:[IFirstCell class]]) {
                    cell = (IFirstCell *)obj;
                    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                        [cell setSeparatorInset:UIEdgeInsetsZero];
                    }
                    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                        [cell setLayoutMargins:UIEdgeInsetsZero];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    break;
                }
            }
        }
        
        cell.delegate = self;
        [cell setCellWithIndexPath:indexPath];
        [cell.photoImage sd_setImageWithURL:[NSURL URLWithString:_firstPhoto] placeholderImage:ECIMAGENAME(@"mine_place.png")];
        return cell;
    }else if (indexPath.section == 1){
        static NSString *reuseIdentifier = @"isecondCell";
        ISecondCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (nil == cell) {
            NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"ISecondCell" owner:nil options:nil];
            for (NSObject *obj in arr) {
                if ([obj isKindOfClass:[ISecondCell class]]) {
                    cell = (ISecondCell *)obj;
                    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                        [cell setSeparatorInset:UIEdgeInsetsZero];
                    }
                    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                        [cell setLayoutMargins:UIEdgeInsetsZero];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    break;
                }
            }
        }
        
        cell.delegate = self;
        [cell setCellWithIndexPath:indexPath];
        [cell.photoImage sd_setImageWithURL:[NSURL URLWithString:_secondPhoto] placeholderImage:ECIMAGENAME(@"mine_place.png")];
        return cell;

    }else if (indexPath.section == 2){
        static NSString *reuseIdentifier = @"ithirdCell";
        IThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (nil == cell) {
            NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"IThirdCell" owner:nil options:nil];
            for (NSObject *obj in arr) {
                if ([obj isKindOfClass:[IThirdCell class]]) {
                    cell = (IThirdCell *)obj;
                    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                        [cell setSeparatorInset:UIEdgeInsetsZero];
                    }
                    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                        [cell setLayoutMargins:UIEdgeInsetsZero];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    break;
                }
            }
        }
        
        cell.delegate = self;
        [cell setCellWithIndexPath:indexPath];
        [cell.photoImage sd_setImageWithURL:[NSURL URLWithString:_thirdPhoto] placeholderImage:ECIMAGENAME(@"mine_place.png")];
        return cell;
    }else{
        static NSString *reuseIdentifier = @"ifourthCell";
        IFourthCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (nil == cell) {
            NSArray *arr = [[NSBundle mainBundle]loadNibNamed:@"IFourthCell" owner:nil options:nil];
            for (NSObject *obj in arr) {
                if ([obj isKindOfClass:[IFourthCell class]]) {
                    cell = (IFourthCell *)obj;
                    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                        [cell setSeparatorInset:UIEdgeInsetsZero];
                    }
                    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                        [cell setLayoutMargins:UIEdgeInsetsZero];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    break;
                }
            }
        }
        
        cell.delegate = self;
        [cell setCellWithIndexPath:indexPath];
        [cell.photoImage sd_setImageWithURL:[NSURL URLWithString:_fourthPhoto] placeholderImage:ECIMAGENAME(@"mine_place.png")];
        return cell;
    }
}


- (void)firstSaveClick:(UIButton *)save Name:(NSString *)name ID:(NSString *)id
{
    if(name.length == 0){
        SHOW_ALERT(@"提示", @"请输入姓名", @"好的", nil, nil);
    }else if (id.length == 0){
        SHOW_ALERT(@"提示", @"请输入身份证号码", @"好的", nil, nil);
    }else if (_firstId.length == 0){
        SHOW_ALERT(@"提示", @"请上传照片凭证", @"好的", nil, nil);
    }else{
        NSDictionary *param = @{
                                @"member_Id":_userInfo.memberModel.member_Id,
                                @"id_card_imgId":_firstId,
                                @"id_card_type":@"身份证",
                                @"real_name":name,
                                @"id_card_no":id,
                                };
        
        [[HttpManager defaultManager] postRequestToUrl:RequestURL(UPDATEMINE) params:param complete:^(BOOL successed, NSDictionary *result) {
            if (successed){
                if ([result[@"errCode"] integerValue] == 200) {
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }
}

- (void)firstCancleClick:(UIButton *)cancle
{
    _firstId = @"";
    _firstPhoto = @"";

    UIButton *button = [self.view viewWithTag:0];
    [self sectionClick:button];
}

- (void)secondSaveClick:(UIButton *)save
{
    if (_secondId.length == 0) {
        SHOW_ALERT(@"提示", @"请上传照片凭证", @"好的", nil, nil);
    }else{
        NSDictionary *param = @{
                                @"member_Id":_userInfo.memberModel.member_Id,
                                @"education_imgId":_secondId,
                                };
        
        [[HttpManager defaultManager] postRequestToUrl:RequestURL(UPDATEMINE) params:param complete:^(BOOL successed, NSDictionary *result) {
            if (successed){
                if ([result[@"errCode"] integerValue] == 200) {
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }
}


- (void)secondCancleClick:(UIButton *)cancle
{
    _secondId = @"";
    _secondPhoto = @"";

    UIButton *button = [self.view viewWithTag:1];
    [self sectionClick:button];
}


- (void)thirdSaveClick:(UIButton *)save
{
    if (_thirdId.length == 0) {
        SHOW_ALERT(@"提示", @"请上传照片凭证", @"好的", nil, nil);
    }else{
        NSDictionary *param = @{
                                @"member_Id":_userInfo.memberModel.member_Id,
                                @"to_teach_imgId":_thirdId,
                                };
        
        [[HttpManager defaultManager] postRequestToUrl:RequestURL(UPDATEMINE) params:param complete:^(BOOL successed, NSDictionary *result) {
            if (successed){
                if ([result[@"errCode"] integerValue] == 200) {
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }
}

- (void)thirdCancleClick:(UIButton *)cancle
{
    _thirdId = @"";
    _thirdPhoto = @"";

    UIButton *button = [self.view viewWithTag:2];
    [self sectionClick:button];
}


- (void)fourthSaveClick:(UIButton *)save
{
    if (_fourthId.length == 0) {
        SHOW_ALERT(@"提示", @"请上传照片凭证", @"好的", nil, nil);
    }else{
        NSDictionary *param = @{
                                @"member_Id":_userInfo.memberModel.member_Id,
                                @"professional_qualifications_imgId":_fourthId,
                                };
        
        [[HttpManager defaultManager] postRequestToUrl:RequestURL(UPDATEMINE) params:param complete:^(BOOL successed, NSDictionary *result) {
            if (successed){
                if ([result[@"errCode"] integerValue] == 200) {
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }
}


- (void)fourthCancleClick:(UIButton *)cancle
{
    _fourthId = @"";
    _fourthPhoto = @"";

    UIButton *button = [self.view viewWithTag:3];
    [self sectionClick:button];
}


- (void)firstPhotoClick:(UIButton *)photo
{
    _photoActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册", @"相机",nil];
    [_photoActionSheet showInView:self.view];
    chooseNum = 1;
}


- (void)secondPhotoClick:(UIButton *)photo
{
    _photoActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册", @"相机",nil];
    [_photoActionSheet showInView:self.view];
    chooseNum = 2;
}


- (void)thirdPhotoClick:(UIButton *)photo
{
    _photoActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册", @"相机",nil];
    [_photoActionSheet showInView:self.view];
    chooseNum = 3;
}


- (void)fourthPhotoClick:(UIButton *)photo
{
    _photoActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册", @"相机",nil];
    [_photoActionSheet showInView:self.view];
    chooseNum = 4;
}



- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{        switch (buttonIndex)
    {
        case 0:
        {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
            {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
                picker.delegate = self;
                picker.allowsEditing = YES;
                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                [self presentViewController:picker animated:YES completion:nil];
            }
        }
            break;
            
        case 1:
        {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
                picker.delegate = self;
                picker.allowsEditing = YES;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self presentViewController:picker animated:YES completion:nil];
            }
        }
            break;
            
        default:
            break;
    }
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    
    dispatch_async(queue, ^{
        
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
        {
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }
        
        if (UIImagePNGRepresentation(image))
        {
            UIImage *newImage = [ECHelper imageWithImageSimple:image scaledToSize:CGSizeMake(320.0f, 320.0f)];
            _imageData = UIImagePNGRepresentation(newImage);
        }
        else
        {
            UIImage *newImage = [ECHelper imageWithImageSimple:image scaledToSize:CGSizeMake(320.0f, 320.0f)];
            _imageData = UIImageJPEGRepresentation(newImage, 0.75);
        }
        
    });
    
#warning ******************POSTPIC********************
    [self dismissViewControllerAnimated:YES completion:^{
        
        NSString *strRandomName = [NSString stringWithFormat:@"iOS_uploadImage_%d.jpg",arc4random_uniform(10000)];
        
        NSArray *files = @[
                           @{
                               @"name": strRandomName,
                               @"file": _imageData ,
                               @"key": @"image",
                               @"type": @"multipart/form-data"
                               }
                           ];
        
        [[HttpManager defaultManager] uploadToUrl:RequestURL(POSTPIC) params:nil files:files complete:^(BOOL successed, NSDictionary *result) {
            if (successed) {
                if ([result[@"errCode"] integerValue] == 0) {
                    switch (chooseNum) {
                        case 1:
                        {
                            _firstPhoto = result[@"path"];
                            _firstId = result[@"pictures_ID"];
                        }
                            break;
                        case 2:
                        {
                            _secondPhoto = result[@""];
                            _secondId = result[@"pictures_ID"];
                        }
                            break;
                        case 3:
                        {
                            _thirdPhoto = result[@""];
                            _thirdId = result[@"pictures_ID"];
                        }
                            break;
                        case 4:
                        {
                            _fourthPhoto = result[@""];
                            _fourthId = result[@"pictures_ID"];
                        }
                            break;

                            
                        default:
                            break;
                    }
                    
                    [_tableView reloadData];
                }else{
                    SHOW_ALERT(@"提示", result[@"errMsg"], @"好的", nil, nil);
                }
            }
        }];
    }];
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
